package org.jeecg.modules.api.wlhy.debang.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.api.wlhy.debang.entity.DbOrder;
import org.jeecg.modules.api.wlhy.debang.service.IDbOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
* @Description: db_order
* @Author: jeecg-boot
* @Date:   2023-08-12
* @Version: V1.0
*/
@RestController
@RequestMapping("/debang/token")
@Slf4j
public class DbTokenController  {

    @Autowired
    private RedisUtil redisUtil;

     //德邦秘钥
    public static final String USERNAME = "2783SDzXC23";
    //密码
    public static final String SECRET = "590h5rz3r1s";
    /**
    *
    */
   @ApiOperation(value="德邦获取token", notes="德邦获取token")
   @GetMapping(value = "/getToken")
   public Result<?> queryPageList(
                                  @RequestParam(name="username") String username,
                                  @RequestParam(name="secret") String secret,
                                  HttpServletRequest req) {

       if(StringUtils.isEmpty(username)||StringUtils.isEmpty(secret)){
           return Result.error("账号密码错误");
       }else if(!username.equals(USERNAME)||!secret.equals(SECRET)){
           return Result.error("账号密码错误");
       }
       // 生成token
       String token = JwtUtil.sign(username, secret);
       // 设置超时时间
       redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
       redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
       return Result.OK(token);
   }




}
